<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['jigouid']){
	$jigouid=$this->checklogin($_RQ['jigouid']);
}elseif($_SESSION['jigouid']){
	$jigouid=$this->checklogin();
}else{
	$jigouid=pdo_getcolumn('jy_chengedu_jigou',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
	if(!$jigouid){
		exi('您还未注册店铺','error',custom_url('jy_chengedu/register/',true));
		$info=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('mobile','nickname','realname'));
		pdo_insert('jy_chengedu_jigou',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1,'jointime'=>time(),'realname'=>$info['realname'],'mobile'=>$info['mobile'],'title'=>$info['nickname']));
		$jigouid=pdo_insertid();
	}
	$_SESSION['jigouid']=$_SESSION['jigouid']?:$jigouid;
}
$return['item']=pdo_get('jy_chengedu_jigou',array('id'=>$jigouid,'uniacid'=>$_SESSION['uniacid']));
$return['isopenvoice']=$return['item']['isopenvoice'];
$return['schools']=pdo_getall('jy_chengedu_jigou',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
$return['plugin_icon']=$return['item']['logo'];
$this->session('plugin_icon',$return['item']['logo']);
$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
$return['item']['logo']=$return['item']['logo']?$return['item']['logo']:$avatar;
$return['status1']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid'],'jigouid'=>$jigouid,'status'=>1));
$return['status2']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid'],'jigouid'=>$jigouid,'status'=>2));
//计算待结算金额
$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>3);
$ids=pdo_getall('jy_chengedu_students',$params,'id','id');
$params=array('uniacid'=>$_SESSION['uniacid'],'jigouid'=>$jigouid,'clearstatus'=>0);
if($ids){
		$ids=array_keys($ids);
		$params['orderid']=$ids;
}
$clearfee0=0;
$commission_money0=0;
$return['clearfee0']=price($clearfee0);
$return['commission_money0']=price($commission_money0);
if($_SESSION['os']=='windows'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$access['status_day']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime));
	$access['status_all']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid']));
	$access['status1_day']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3),'createtime >'=>$daytime));
	$access['status1_all']=pdo_count('jy_chengedu_students',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3)));
	//月份
	for($i=0;$i<12;$i++){
				if($i==0){
					$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
					$yueend = time();
					
				}else{
					$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
					$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
				}
				$params=array('uniacid'=>$_SESSION['uniacid']);
				$params['createtime between']=array($yuestart,$yueend);
				$month12[$i] = date('Y-m',strtotime('-'.$i.' month'));
				//$monthaccess[]=pdo_count('core_access_log',$params);
				$accessline[$i]=pdo_count('jy_chengedu_students',$params);
				//$monthcredit2[]=pdo_getsum('core_members',$params,'credit2');
	}
	$accessline=array_reverse($accessline);
	$month12=array_reverse($month12);
	$htmls=array(
				array('type'=>'data','tpltype'=>4,'one_num'=>4,'title'=>'今日/总订单数据指标','datas'=>array(
					array('title'=>'今日/总订单数','num'=>2,'data'=>array($access['status_day'],$access['status_all']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'今日/总成交数','bgcolor'=>'#009933','num'=>2,'data'=>array($access['status1_day'],$access['status1_all']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'待发货/收货数','bgcolor'=>'#3366FF','num'=>2,'data'=>array($return['status1'],$return['status2']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'今日/总订单数','bgcolor'=>'#FF3300','num'=>2,'data'=>array($access['pc_day'],$access['status_all']),'datatitle'=>array('客户数','申请数')),
				)),
				array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'月度订单数据','datas'=>array(
					'datas'=>array(
						array('name'=>'订单数','value'=>$accessline),
					),
					'xdatas'=>$month12,
				)),
	);	
	$return['htmls']=$htmls;
}
set_html('title','机构后台');
exi($return);